<template>
    <div class="publicpageview">
        <div class="publicformview">
            <el-form :inline="true" :model="listQuery" size="mini" ref="searchForm">
                <el-row :gutter="20">
                    <el-col :span="4">
                        <el-form-item label="系统菜单：" prop="status">
                            <el-select v-model="listQuery.status">
                                <el-option label="发布" value="1" key="1"></el-option>
                                <el-option label="不发布" value="0" key="0"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="操作人员：" prop="status">
                            <el-select v-model="listQuery.status">
                                <el-option label="发布" value="1" key="1"></el-option>
                                <el-option label="不发布" value="0" key="0"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="4">
                        <el-form-item label="操作类型：" prop="status">
                            <el-select v-model="listQuery.status">
                                <el-option label="发布" value="1" key="1"></el-option>
                                <el-option label="不发布" value="0" key="0"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="状态：" prop="status">
                            <el-select v-model="listQuery.status">
                                <el-option label="发布" value="1" key="1"></el-option>
                                <el-option label="不发布" value="0" key="0"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="4">
                        <el-form-item label="操作时间：" prop="times">
                            <el-date-picker v-model="listQuery.times" type="date" placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>


                    <el-col :span="4">
                        <div>
                            <el-button size="mini" type="primary">查询</el-button>
                            <el-button size="mini" @click="resetForm('searchForm')">重置</el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-form>
        </div>

        <div class="publitableview">
            <el-button type="primary" size="mini" @click="handleAddUser('add')">导出日志</el-button>
            <el-table v-loading="listLoading" :data="list" border fit highlight-current-row size="mini">
                <el-table-column align="center" label="日志编号" prop="userId">
                </el-table-column>

                <el-table-column align="center" label="系统菜单" prop="userName">
                </el-table-column>

                <el-table-column align="center" label="操作人员" prop="phone">
                </el-table-column>
                <el-table-column align="center" label="操作类型" prop="userStatus">
                    <template slot-scope="scope">
                        <span>{{ scope.row.userStatus == 0 ? "禁用" : "启用" }}</span>
                    </template>
                </el-table-column>


                <el-table-column align="center" label="操作时间" prop="phone">
                </el-table-column>

                <el-table-column align="center" label="操作状态" prop="deptId">
                    <template slot-scope="scope">
                        <span>{{ deptName(scope.row.deptId) }}</span>
                    </template>
                </el-table-column>

                <el-table-column align="center" label="操作" width="100">
                    <template slot-scope="scope">
                        <el-button type="text" size="mini" @click="handleUpdate(scope.row,'details')">详情</el-button>
                        <el-button type="text" size="mini" @click="handleDelete(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <div class="publicpaginationview">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="listQuery.page" background :page-sizes="[10, 20, 50, 100]"
                    :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total"
                    small></el-pagination>
            </div>
        </div>

        <el-dialog :title="isAdd == 'add' ? '新增用户' : isAdd == 'update' ? '修改用户' : '用户详情'" :visible.sync="dialogVisible"
            width="40%" :before-close="handleClose">
            <el-form :model="formData" ref="dataForm" class="demo-ruleForm" label-position="right" label-width="120px"
                size="mini">
                <el-form-item label="系统菜单：" prop="userId">
                    <el-input v-model="formData.userId" disabled></el-input>
                </el-form-item>
                <el-form-item label="操作人员：" prop="userName">
                    <el-input v-model="formData.userName"></el-input>
                </el-form-item>
                <el-form-item label="操作类型：" prop="phone">
                    <el-input v-model.number="formData.phone"></el-input>
                </el-form-item>

                <el-form-item label="操作时间：" prop="phone">
                    <el-input v-model.number="formData.phone"></el-input>
                </el-form-item>



                <el-form-item label="状态：" prop="userStatus">
                    <el-select v-model="formData.userStatus">
                        <el-option label="启用" value="1" key="1"></el-option>
                        <el-option label="禁用" value="0" key="0"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="dialogVisible = false" size="medium" v-if="isAdd == 'details'">返
                    回</el-button>

                <el-button type="primary" @click="dialogVisible = false" size="medium" v-else>保 存</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "AccommodationManagementIndex",

    data() {
        return {
            listQuery: {
                page: 1,
                limit: 20,
                keyword: "",
                mobile: "",
                status: "1",
                times: ""
            },
            total: 0,
            options: [{ key: "1" }],
            list: [
                {
                    userId: 0,
                    userName: "吴晓华",
                    userStatus: "0",
                    phone: "13807300130",
                    remarks: "此角色为测试角色",
                    roleId: "1",
                    deptId: "1",
                },
            ],
            listLoading: false,
            dialogVisible: false,
            isAdd: 'add',
            formData: {
                userId: "",
                userName: "",
                phone: "",
                deptId: "",
                roleId: "",
                userStatus: "1",
                remarks: "",
            },
        };
    },

    computed: {
        deptName() {
            return (val) => {
                if (val == "1") {
                    return "事业部";
                }
                return "生活部";
            };
        },
    },

    mounted() {
        this.total = this.list.length;
    },

    methods: {
        handleSizeChange(val) {
            this.listQuery.page = 1;
            this.listQuery.limit = val;
            this.getList();
        },
        handleCurrentChange(val) {
            this.listQuery.page = val;
            this.getList();
        },
        getList() {
            this.listLoading = true;
            newsPage(this.listQuery).then((response) => {
                this.total = response.data.total;
                this.list = response.data.list;
                this.listLoading = false;
            });
        },

        resetForm(val) {

            this.$refs[val].resetFields();
        },

        handleAddUser(type) {
            this.isAdd = 'add';
            this.dialogVisible = true;
        },

        handleClose() {
            this.resetForm("dataForm");
            this.dialogVisible = false;
        },

        handleUpdate(currentData, type) {
            this.isAdd = type;
            //   一定要在打开弹窗前 再赋值 不然resetFiles没用
            this.dialogVisible = true;
            this.$nextTick(() => {
                this.formData = { ...currentData };
            });
        },

        handleDelete(id) {
            this.$confirm(
                "此操作将删除该条内容，请确认是否继续操作？",
                "删除提示",
                {
                    confirmButtonText: "保 存",
                    cancelButtonText: "取 消",
                    type: "warning",
                }
            )
                .then(() => {

                })
                .catch(() => { });
        }
    },
};
</script>